package edu.ccut.titan.core;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import edu.ccut.titan.core.impl.ComponentResolver;
import edu.ccut.titan.core.impl.ResourcesResolver;
import edu.ccut.titan.service.ITitanPropertiesService;
import edu.ccut.titan.service.ServiceFactory;

public class TitanActivator implements BundleActivator {

	private ComponentResolver componentResolver;

	private ResourcesResolver resourcesResolver;

	private ITitanPropertiesService titanPropertiesService = null;

	public static Bundle BUNDLE = null;

	public TitanActivator() {
		this.componentResolver = new ComponentResolver();
		this.resourcesResolver = new ResourcesResolver();
	}

	public final void start(BundleContext context) throws Exception {
		BUNDLE = context.getBundle();

		this.titanPropertiesService = ServiceFactory
				.geTitanPropertiesService(context);
		this.componentResolver.loadComponent(context);
	//	this.resourcesResolver.loadResource(context.getBundle(), this.titanPropertiesService);

		this.doStart(context);
	}

	public final void stop(BundleContext context) throws Exception {
		this.componentResolver.unlodaComponent(context);
	//	this.resourcesResolver.unloadResource(context.getBundle(), this.titanPropertiesService);

		this.titanPropertiesService = null;
		this.doStop(context);
	}

	/**
	 * 当启动Bundles时需要加入某些操作,请重写此方法
	 * 
	 * @param context
	 */
	protected void doStart(BundleContext context) throws Exception {

	}

	/**
	 * 当停止bundles时需要加入某些操作,请重写此方法
	 * 
	 * @param context
	 */
	protected void doStop(BundleContext context) throws Exception {

	}
}
